<?php

namespace App\Http\Requests\Api;

class ResumeEducationExpRequest extends ApiRequest
{
    /**
     * Get the validation rules that apply to the request.
     *
     * @return array
     */
    public function rules()
    {
        return [
            'id' => $this->is('*/update') ? 'bail|required|integer' : '',
            'resume_id' => $this->is('*/create') ? 'bail|required|integer' : '',
            'edu_type'=>'bail|required|integer|between:1,2',
            'school' => 'required',
            'starttime' => 'bail|required|before:now',
            'endtime' => 'bail|required' . ($this->endtime == '0000-00-00' ? '' : '|after:starttime'),
            'speciality' => 'required',
            'education' => 'bail|required_if:edu_type,1|integer',
            'type' => 'bail|required_if:edu_type,1|integer|between:0,1',
        ];
    }

    /*
     * 字段描述
     */
    public function attributes()
    {
        return [
            'school' => $this->edu_type==1?'学校名称':'培训机构',
            'starttime' => '入学时间',
            'endtime' => '毕业时间',
            'speciality' => $this->edu_type==1?'专业名称':'培训项目',
            'education' => '学历',
            'type' => '是否统招',
            'edu_type'=>'教育类型',
        ];
    }

    public function messages()
    {
        return array_merge(parent::messages(),[
            'starttime.before'=>':attribute不能小于现在',
            'endtime.after' => '毕业时间不能小于入学时间'
        ]);
    }
}
